﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Scheduler;

namespace CoursePack
{
    [Serializable]
    public class Degree : DegreeDescription
    {
        #region Data

        private List<Semester> m_Semesters;
        private CourseSequence m_CourseSequence;
        private List<CourseDescription> m_CoursesDone;

        #endregion

        public Degree(CourseSequence _CourseSequence,Department _Department,EnumDegree _Deg) 
            : base(_Department,_Deg)
        { 
            this.m_Semesters = new List<Semester>();
            this.m_CoursesDone = new List<CourseDescription>();
            this.m_CourseSequence = _CourseSequence;

            
        }

        public Semester CreateSemester(SavedSchedule _Schedule, Session _Session)
        {
            Semester semester = new Semester(_Schedule,_Session);
            this.m_Semesters.Add(semester);

            return semester;
        }

        public bool AddCompletedCourse(CourseDescription _Course)
        {
            if (this.m_CoursesDone.Find(o => o == _Course) == null)
            {
                this.m_CoursesDone.Add(_Course);
                return true;
            }
            else 
                return false;
        }

        public Semester GetSemester(Session _Session)
        {
            return this.m_Semesters.Find(o => ((o.Session == _Session.ESession) && o.Year == _Session.Year));
        }

        public float GetMaxCreditsAllowed(Session _Session)
        {
            switch (_Session.ESession)
            {
                case ESession.Summer :
                    return 15.5f;
                    break;
                default :
                    return 19.5f;
                    break;
            }
        }

        #region Private Methods

        #endregion

        #region Accessors
        public List<CourseDescription> CoursesDone
        {
           get {
               /*
               List<Course> tmp = new List<Course>();

               foreach (Semester semester in this.m_Semesters)
               {
                   foreach (Course course in semester.Schedule.Courses)
                   {
                       if (course.IsCompleted)
                       {
                           tmp.Add(course);
                       }
                   }
               }
               return tmp;*/
               return this.m_CoursesDone;

           }

        }

        public CourseSequence CourseSequence
        {
            get { return this.m_CourseSequence; }
            set { this.m_CourseSequence = value; }
        }
        
        #endregion  

        
    }
}
